/*     */ package com.feeyin.radar.sys.controller;
/*     */ 
/*     */ import com.feeyin.radar.commons.FinalUtils;
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.crm.service.ContractService;
/*     */ import com.feeyin.radar.listener.OnlineUserListener;
/*     */ import com.feeyin.radar.sys.model.Operate;
/*     */ import com.feeyin.radar.sys.model.Users;
/*     */ import com.feeyin.radar.sys.service.CommonSettingsService;
/*     */ import com.feeyin.radar.sys.service.FunctionTreeService;
/*     */ import com.feeyin.radar.sys.service.OnlineUserService;
/*     */ import com.feeyin.radar.sys.service.OperateService;
/*     */ import com.feeyin.radar.sys.service.UserService;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletContext;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import javax.servlet.http.HttpSession;
/*     */ import org.springframework.web.servlet.ModelAndView;
/*     */ import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
/*     */ import org.springframework.web.servlet.view.RedirectView;
/*     */ 
/*     */ public class LoginController extends MultiActionController
/*     */ {
/*     */   private UserService userService;
/*     */   private FunctionTreeService functionTreeService;
/*     */   private OperateService operateService;
/*     */   private CommonSettingsService commonSettingsService;
/*     */   private ContractService contractService;
/*     */   private OnlineUserListener onlineUserListener;
/*     */   private OnlineUserService onlineUserService;
/*     */   private String login;
/*     */ 
/*     */   public UserService getUserService()
/*     */   {
/*  46 */     return this.userService;
/*     */   }
/*     */ 
/*     */   public void setUserService(UserService userService) {
/*  50 */     this.userService = userService;
/*     */   }
/*     */ 
/*     */   public FunctionTreeService getFunctionTreeService() {
/*  54 */     return this.functionTreeService;
/*     */   }
/*     */ 
/*     */   public void setFunctionTreeService(FunctionTreeService functionTreeService) {
/*  58 */     this.functionTreeService = functionTreeService;
/*     */   }
/*     */ 
/*     */   public OperateService getOperateService() {
/*  62 */     return this.operateService;
/*     */   }
/*     */ 
/*     */   public void setOperateService(OperateService operateService) {
/*  66 */     this.operateService = operateService;
/*     */   }
/*     */ 
/*     */   public CommonSettingsService getCommonSettingsService() {
/*  70 */     return this.commonSettingsService;
/*     */   }
/*     */ 
/*     */   public void setCommonSettingsService(CommonSettingsService commonSettingsService) {
/*  74 */     this.commonSettingsService = commonSettingsService;
/*     */   }
/*     */ 
/*     */   public ContractService getContractService() {
/*  78 */     return this.contractService;
/*     */   }
/*     */ 
/*     */   public void setContractService(ContractService contractService) {
/*  82 */     this.contractService = contractService;
/*     */   }
/*     */ 
/*     */   public OnlineUserListener getOnlineUserListener() {
/*  86 */     return this.onlineUserListener;
/*     */   }
/*     */ 
/*     */   public void setOnlineUserListener(OnlineUserListener onlineUserListener) {
/*  90 */     this.onlineUserListener = onlineUserListener;
/*     */   }
/*     */ 
/*     */   public OnlineUserService getOnlineUserService() {
/*  94 */     return this.onlineUserService;
/*     */   }
/*     */ 
/*     */   public void setOnlineUserService(OnlineUserService onlineUserService) {
/*  98 */     this.onlineUserService = onlineUserService;
/*     */   }
/*     */ 
/*     */   public String getLogin() {
/* 102 */     return this.login;
/*     */   }
/*     */ 
/*     */   public void setLogin(String login) {
/* 106 */     this.login = login;
/*     */   }
/*     */ 
/*     */   public ModelAndView display(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 111 */     Map map = new HashMap();
/* 112 */     map.put("loginFail", request.getAttribute("loginFail"));
/*     */ 
/* 114 */     return new ModelAndView(getLogin(), map);
/*     */   }
/*     */ 
/*     */   public ModelAndView submitLogin(HttpServletRequest request, HttpServletResponse response, Users user)
/*     */   {
/* 119 */     Integer userCount = this.onlineUserService.getPageOnlineUsersCount();
/* 120 */     if ((userCount != null) && (userCount.intValue() >= FinalUtils.ONLINEUSERNUM)) {
/* 121 */       request.setAttribute("loginFail", Integer.valueOf(2));
/* 122 */       request.setAttribute("user", user);
/* 123 */       return display(request, response);
/*     */     }
/*     */ 
/* 126 */     if ((user != null) && 
/* 127 */       (!StringUtils.isEmpty(user.getUserCode())) && 
/* 128 */       (!StringUtils.isEmpty(user.getPassword())))
/*     */     {
/* 130 */       Users oldUser = new Users();
/* 131 */       oldUser = this.userService.checkedUser(user);
/* 132 */       if (oldUser != null) {
/* 133 */         request.getSession().setAttribute("userId", oldUser.getId());
/* 134 */         request.getSession().setAttribute("userName", oldUser.getUserName());
/* 135 */         request.getSession().setAttribute("creditLevel", oldUser.getCreditLevel());
/* 136 */         request.getSession().setAttribute("lastLogin", oldUser.getLastLoginDate());
/*     */ 
/* 138 */         String locale = request.getParameter("locale");
/* 139 */         int language = 1;
/* 140 */         if ((!StringUtils.isEmpty(locale)) && ("en_US".equals(locale))) {
/* 141 */           language = 2;
/*     */         }
/* 143 */         request.getSession().setAttribute("language", Integer.valueOf(language));
/*     */ 
/* 145 */         checkOnlineUser(request);
/*     */ 
/* 147 */         int isUseCommon = this.commonSettingsService.isUseCommons();
/* 148 */         int isMoveToExceptionPool = this.commonSettingsService.isMoveToExceptionPool();
/* 149 */         if ((isUseCommon <= 0) || (isMoveToExceptionPool == 1))
/*     */         {
/* 151 */           this.functionTreeService.updateFunctionByFunctionCode("OpenCustomer", "0");
/*     */         }
/*     */         else {
/* 154 */           this.functionTreeService.updateFunctionByFunctionCode("OpenCustomer", "1");
/*     */         }
/*     */ 
/* 164 */         request.getSession().setAttribute("isUseCommon", Integer.valueOf(isUseCommon));
/* 165 */         request.getSession().setAttribute("isExceptionPool", Integer.valueOf(isMoveToExceptionPool));
/*     */ 
/* 167 */         userFunctionOperate(request);
/*     */ 
/* 172 */         String updateAgingDate = (String)getServletContext().getAttribute("updatAgingDate");
/* 173 */         String strUpdateDate = this.contractService.updateAllContractAging(updateAgingDate);
/* 174 */         getServletContext().setAttribute("updatAgingDate", strUpdateDate);
/*     */ 
/* 176 */         return new ModelAndView(new RedirectView("./index.do"));
/*     */       }
/*     */     }
/*     */ 
/* 180 */     request.setAttribute("loginFail", Integer.valueOf(1));
/* 181 */     request.setAttribute("user", user);
/* 182 */     return display(request, response);
/*     */   }
/*     */ 
/*     */   public ModelAndView logout(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 187 */     HttpSession session = request.getSession();
/* 188 */     if (session != null)
/*     */     {
/* 190 */       Integer userId = (Integer)request.getSession().getAttribute("userId");
/* 191 */       if (userId != null) this.userService.updateUserLastLoginDate(userId);
/* 192 */       session.invalidate();
/*     */     }
/* 194 */     return new ModelAndView(new RedirectView("./login.do"));
/*     */   }
/*     */ 
/*     */   private void userFunctionOperate(HttpServletRequest request)
/*     */   {
/* 199 */     Integer userId = (Integer)request.getSession().getAttribute("userId");
/*     */ 
/* 201 */     List functions = new ArrayList();
/* 202 */     List operates = new ArrayList();
/* 203 */     if (userId != null) {
/* 204 */       functions = this.functionTreeService.getFunctionsByUserId(userId);
/* 205 */       operates = this.operateService.getOperatesByUserId(userId);
/* 206 */       if ((operates != null) && (operates.size() > 0)) {
/* 207 */         for (int i = 0; i < operates.size(); i++) {
/* 208 */           Operate operate = new Operate();
/* 209 */           operate = (Operate)operates.get(i);
/* 210 */           request.getSession().setAttribute(operate.getOperateCode(), operate.getIsActivity());
/*     */         }
/*     */       }
/*     */     }
/* 214 */     request.getSession().setAttribute("functionTree", functions);
/*     */   }
/*     */ 
/*     */   private void checkOnlineUser(HttpServletRequest request)
/*     */   {
/* 222 */     HttpSession session = request.getSession();
/* 223 */     Integer userId = (Integer)session.getAttribute("userId");
/* 224 */     if (!this.onlineUserListener.existUser(userId, session))
/* 225 */       session.setAttribute(userId.toString(), this.onlineUserListener);
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.controller.LoginController
 * JD-Core Version:    0.6.0
 */